<?php

App::uses('AppModel', 'Model');

/**
 * Document Model
 *
 * @property User $User
 */
class Document extends AppModel {

    /**
     * Display field
     *
     * @var string
     */
    public $displayField = 'id';

    /**
     * Validation rules
     *
     * @var array
     */
    public $validate = array(
        'filename' => array(
            'isValidExtension' => array(
                'rule' => array('isValidExtension', array('pdf', 'doc', 'docx', 'png', 'jpg', 'pjpeg', 'gif')),
                'message' => 'File has an invalid extension'
            ),
            'isValidMimeType' => array(
                'rule' => array('isValidMimeType', array('application/pdf', 'application/msword', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif')),
                'message' => 'File is of an invalid mimetype'
            ),
            'isBelowMaxSize' => array(
                'rule' => array('isBelowMaxSize', 20971520),
                'message' => 'File is larger than the maximum filesize'
            )
        ),
    );

    /**
     *
     * @var array 
     */
    public $actsAs = array(
        'Upload.Upload' => array(
            'filename' => array(
                'path' => '{ROOT}webroot{DS}files{DS}{model}{DS}{field}{DS}',
                'fields' => array('dir' => 'dir', 'type' => 'minetype', 'size' => 'filesize'),
                'mimetypes' => array('application/pdf', 'application/msword', 'image/pjpeg', 'image/png', 'image/gif'),
                'extensions' => array('pdf', 'doc', 'docx', 'jpg'),
                'maxSize' => 20971520
            )
        )
    );

    /**
     * hasAndBelongsToMany associations
     *
     * @var array
     */
    public $hasAndBelongsToMany = array(
        'User' => array(
            'className' => 'User',
            'joinTable' => 'user_documents',
            'foreignKey' => 'document_id',
            'associationForeignKey' => 'user_id',
            'unique' => 'keepExisting',
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'finderQuery' => '',
            'deleteQuery' => '',
            'insertQuery' => ''
        )
        );
    

}
